/*
 * Powered By [rapid-framework]
 * Web Site: http://www.rapid-framework.org.cn
 * Google Code: http://code.google.com/p/rapid-framework/
 * Since 2008 - 2017
 */

package com.database.management.service.impl;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;

import com.database.management.dao.jpa.SqlStatementRepository;
import com.database.management.domain.SqlStatement;
import com.database.management.service.ISqlStatementService;


@Service
public class SqlStatementServiceImpl implements ISqlStatementService{
private Logger log = LoggerFactory.getLogger(SqlStatementServiceImpl.class);
	
	@Autowired
	private SqlStatementRepository sqlStatementRepository;

	@Override
	public void delete(Integer id) {
		sqlStatementRepository.delete(id);
	}

	@Override
	public SqlStatement insert(SqlStatement record) {
		return sqlStatementRepository.save(record);
	}

	@Override
	public SqlStatement update(SqlStatement record) {
		return sqlStatementRepository.saveAndFlush(record);
	}

	@Override
	public SqlStatement findOne(Integer id) {
		return sqlStatementRepository.findOne(id);
	}

	@Override
	public List<SqlStatement> findAll(Example<SqlStatement> example, Sort sort) {
		if (example.getProbe() == null) {
			return sqlStatementRepository.findAll(sort);
		} else {
			return sqlStatementRepository.findAll(example, sort);
		}
	}

	@Override
	public Page<SqlStatement> findPage(Example<SqlStatement> example, Pageable pageable) {
		if (example == null) {
			return sqlStatementRepository.findAll(pageable);
		} else {
			return sqlStatementRepository.findAll(example, pageable);
		}
	}
	
}
